// pages/changmima/changemima.js
Page({

  /**
   * 页面的初始数据
   */
  data: { 
    name:'',
    number:'',
    oldpsd:'',
    newpsd1:'',
    newpsd2:'',
    infor:false,
    text1:'',
    text2:'',
    text3:'',
    text4:'',
    text5:'',

  },
  getUsername:function(t){
    this.setData({
      name:t.detail.value
    })
  },
  getNumber:function(t){
    this.setData({
      number:t.detail.value
    })
  },
  getOldpsd:function(t){
    this.setData({
      oldpsd:t.detail.value
    })
  },
  getNewpsd1:function(t){
    this.setData({
      newpsd1:t.detail.value
    })
  },
  getNewpsd2:function(t){
    this.setData({
      newpsd2:t.detail.value
    })
  },
  change() {
    let name=this.data.name;
    let number=this.data.number;
    let oldpsd=this.data. oldpsd;
    let newpsd1=this.data.newpsd1;
    let newpsd2=this.data.newpsd2;
    if(name===''){
      this.setData({
        text1:"内容不能为空",
        infor:false
      })
    }else{
      this.setData({
        text1:""
      })
    }
    if(number===''){
      this.setData({
        text2:"内容不能为空",
        infor:false
      })
    }else{
      this.setData({
        text2:""
      })
    }
    if(oldpsd===''){
      this.setData({
        text3:"内容不能为空",
        infor:false
      })
    }else{
      this.setData({
        text3:""
      })
    }
    if(newpsd1===''){
      this.setData({
        text4:"内容不能为空",
        infor:false
      })
    }else{
      this.setData({
        text4:""
      })
    }
    if(newpsd2===''){
      this.setData({
        text5:"内容不能为空",
        infor:false
      })
    }else{
      this.setData({
        text5:""
      })
    }
    let sno=wx.getStorageSync('username');
    let username=wx.getStorageSync('name');
    let password=wx.getStorageSync('password');
    if(name===username&&number===sno&&oldpsd===password){
      if(newpsd1===oldpsd){
        this.setData({
          infor:false,
          text4:"与原密码一致，请重新输入",
        })
      }
      if(newpsd1!==newpsd2){
        this.setData({
          infor:false,
          text5:"输入密码不一致，请重新输入",
        })
      }
      
      if(newpsd1!==oldpsd&&newpsd1===newpsd2){
        this.setData({
        infor:true
      })
      }
    }else{
      this.setData({
        infor:false,
        text3:"输入信息不正确，请重新输入",
      })
    }
    console.log(this.data.infor)
   if(this.data.infor){

    wx.showModal({
      title: '提示',
      content: '确定要修改密码吗？',
      success: res=>{
        if (res.confirm) {
          wx.request({
            url:'https://yali.geekwhite.cn:3000/changepsd', 
            header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
            header:{'Access-Control-Allow-Origin':'*'},
            header:{'Access-Control-Allow-Methods':'GET,POST'},
            data: {
              sno:this.data.number,
              psd:this.data. newpsd1
             },
             method: 'post',
             success: res=>{
                  // console.log(res.data.name);
                  console.log(res);
             }
          })
      
      
          wx.navigateTo({
            url: '../changeok/changeok'
           })
        } else if (res.cancel) {
          console.log('取消')
        }
      }
    })
       



   }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})